Feature: Create a new grid
  In order to share a visual grid with others
  As a grid creator
  I want to create a grid first

  Scenario: Show the "new grid" form
    Given I am on the main page
    When I click link "Create a new grid"
    Then I should see a new grid form with name, description and dimensions

  Scenario: Create a new grid
    Given I am on the new grid form
    When I fill text field "grid_name" with "Sample grid"
    And I fill text field "grid_description" with "Sample grid description"
    And I fill text field "grid_rows" with "10"
    And I fill text field "grid_columns" with "10"
    And I click button "Create"
    Then I should see a grid panel

  Scenario: Create a new grid without specifying anything
    Given I am on the new grid form
    When I click button "Create"
    Then I should see "Name can't be blank"
    And I should see "Columns can't be blank"
    And I should see "Rows can't be blank"
    And I should see a new grid form with name, description and dimensions
    And I should not see a grid panel

  Scenario: Create a new grid with not-a-number rows and columns
    Given I am on the new grid form
    When I fill text field "grid_rows" with "blah"
    And I fill text field "grid_columns" with "blah"
    And I click button "Create"
    Then I should see "Rows is not a number"
    And I should see "Columns is not a number"
    And I should see a new grid form with name, description and dimensions
    And I should not see a grid panel

  Scenario: Create a new grid with too long name (max is 30)
    Given I am on the new grid form
    When I fill text field "grid_name" with "1234567890123456789012345678901"
    And I click button "Create"
    Then I should see "Name is too long (maximum is 30 characters)"
    And I should see a new grid form with name, description and dimensions
    And I should not see a grid panel

  Scenario: Create a new grid with too large dimension (max is 50 x 50)
    Given I am on the new grid form
    When I fill text field "grid_rows" with "51"
    And I fill text field "grid_columns" with "51"
    And I click button "Create"
    Then I should see "Rows must be less than or equal to 50"
    And I should see "Columns must be less than or equal to 50"
    And I should see a new grid form with name, description and dimensions
    And I should not see a grid panel

  Scenario: Create a new grid with too small dimension (min is 1 x 1)
    Given I am on the new grid form
    When I fill text field "grid_rows" with "0"
    And I fill text field "grid_columns" with "0"
    And I click button "Create"
    Then I should see "Rows must be greater than or equal to 1"
    And I should see "Columns must be greater than or equal to 1"
    And I should see a new grid form with name, description and dimensions
    And I should not see a grid panel